package com.zuoqi.easywork.projectManage.controller;

import com.github.pagehelper.Page;
import com.zuoqi.common.utils.IMap;
import com.zuoqi.common.utils.PageView;
import com.zuoqi.common.utils.SessionUtil;
import com.zuoqi.easywork.userManage.service.ScheduleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.List;
import java.util.Map;

@Controller
public class myProjectCon {
    @Autowired
    private ScheduleService scheduleService;

    @RequestMapping(value = "/myProjectCon/toPage/myProjectView")
    public String myProjectView(){
        return "/module/projectManage/myProject";
    }

    /**
     * 获得项目列表(部员)
     * */
    @RequestMapping(value = "/myProjectCon/ajax/getProjectList",method = RequestMethod.POST)
    @ResponseBody
    public Map getProjectList(HttpServletRequest request){
        IMap params = new IMap(request);
        HttpSession session = request.getSession();
        String userId = SessionUtil.getLoginUserId(session);
        params.put("userId",userId);
        Page page = PageView.startPageForTable(params, false);
        List<IMap> projectList = scheduleService.getProjectListForUser(params);
        Map<String, Object> result = PageView.getResultForTable(page, projectList);
        return result;
    }
}
